<template>
  <div class="employee">
    <!-- 卡1 -->
    <el-card class="top-card">
      <el-row type="flex" justify="space-between">
        <el-col :span="6">
          <div class="info-box">
            <!-- 图标 -->
            <i class="el-icon-info" />
            <span>共 {{ total }} 条数据</span>
          </div>
        </el-col>
        <el-col :span="6">
          <el-button type="warning">导入</el-button>
          <el-button type="danger">导出</el-button>
          <el-button type="primary">新增员工</el-button>
        </el-col>
      </el-row>
    </el-card>
    <!-- 卡2 -->
    <el-card class="bottom-card">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column fixed label="序号" type="index" width="50" />
        <el-table-column prop="username" label="姓名" width="250" />
        <el-table-column prop="workNumber" label="工号" width="120" />
        <el-table-column prop="formOfEmployment" label="聘用形式" width="250" />
        <el-table-column prop="departmentName" label="部门" width="300" />
        <el-table-column prop="timeOfEntry" label="入职时间" width="250" />
        <!-- 本地接口木有这个字段 -->
        <el-table-column label="账户状态" width="250" />
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="handleClick(scope.row)"
            >查看</el-button>
            <el-button type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        :page-size="size"
        layout="prev, pager, next"
        :total="total"
      />
    </el-card>
  </div>
</template>

<script>
// 导入接口
import { getEmployees } from '@/api/employees'
export default {
  name: 'Employees',
  data() {
    return {
      tableData: [], // table数据
      size: 3, // 页容量
      page: 1, // 页码
      total: 0 // 总条数
    }
  },
  async created() {
    const res = await getEmployees({
      page: this.page,
      size: this.size
    })
    console.log(res)
    this.tableData = res.rows
    this.total = res.total
  },
  methods: {
    handleClick(row) {
      console.log(row)
    }
  }
}
</script>

<style lang="scss">
.employee {
  .bottom-card {
    margin-top: 20px;
  }
  .el-pagination {
    text-align: center;
    margin-top: 20px;
  }
  .el-row {
    align-items: center;
  }
  .info-box {
    border: 1px solid #96d7ff;
    background-color: #e6f7ff;
    border-radius: 4px;
    display: inline-block;
    padding: 4px;
    i {
      color: #5181fb;
    }
  }
}
</style>
